package com.taichuan.selfcheck.entity.file;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 该类主要用于
 *
 * @author CamelLuo
 * @version 2020/7/27
 */
public class FileInfo implements Parcelable {
    private String fileName;
    private String fileSize;
    private String filePermission;
    private String fileDate;
    private long fileLastModified;
    private String filePath;
    private boolean isDirectory;

    public FileInfo(String fileName, String fileSize, String filePermission, String fileDate, long fileLastModified, String filePath, boolean isDirectory) {
        this.fileName = fileName;
        this.fileSize = fileSize;
        this.filePermission = filePermission;
        this.fileDate = fileDate;
        this.fileLastModified = fileLastModified;
        this.filePath = filePath;
        this.isDirectory = isDirectory;
    }

    protected FileInfo(Parcel in) {
        fileName = in.readString();
        fileSize = in.readString();
        filePermission = in.readString();
        fileDate = in.readString();
        fileLastModified = in.readLong();
        filePath = in.readString();
        isDirectory = in.readByte() != 0;
    }

    public boolean isPhotoFile(){
        return isPhotoFile(getFileName());
    }

    private boolean isPhotoFile(String fileName){
        return fileName.contains(".jpg") || fileName.contains(".jpeg") || fileName.contains(".png") ||
                fileName.contains(".gif");
    }

    public static final Creator<FileInfo> CREATOR = new Creator<FileInfo>() {
        @Override
        public FileInfo createFromParcel(Parcel in) {
            return new FileInfo(in);
        }

        @Override
        public FileInfo[] newArray(int size) {
            return new FileInfo[size];
        }
    };

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileSize() {
        return fileSize;
    }

    public void setFileSize(String fileSize) {
        this.fileSize = fileSize;
    }

    public String getFilePermission() {
        return filePermission;
    }

    public void setFilePermission(String filePermission) {
        this.filePermission = filePermission;
    }

    public String getFileDate() {
        return fileDate;
    }

    public void setFileDate(String fileDate) {
        this.fileDate = fileDate;
    }

    public long getFileLastModified() {
        return fileLastModified;
    }

    public void setFileLastModified(long fileLastModified) {
        this.fileLastModified = fileLastModified;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public boolean isDirectory() {
        return isDirectory;
    }

    public void setDirectory(boolean directory) {
        isDirectory = directory;
    }

    @Override
    public String toString() {
        return "FileInfo{" +
                "fileName='" + fileName + '\'' +
                ", fileSize='" + fileSize + '\'' +
                ", filePermission='" + filePermission + '\'' +
                ", fileDate='" + fileDate + '\'' +
                ", fileLastModified=" + fileLastModified +
                ", filePath='" + filePath + '\'' +
                ", isDirectory=" + isDirectory +
                '}';
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(fileName);
        dest.writeString(fileSize);
        dest.writeString(filePermission);
        dest.writeString(fileDate);
        dest.writeLong(fileLastModified);
        dest.writeString(filePath);
        dest.writeByte((byte) (isDirectory ? 1 : 0));
    }
}
